package com.yic.module.base.api.factory;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yic.framework.common.util.collection.CollectionUtils;
import com.yic.module.base.api.factory.dto.FactoryRespDTO;
import com.yic.module.base.convert.factory.FactoryConvert;
import com.yic.module.base.dal.dataobject.factory.FactoryDO;
import com.yic.module.base.service.factory.FactoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @ClassName FactoryApiImpl
 * @Description 工厂接口实现类
 * @Author Lijx
 * @Date 2023/10/20 17:02
 * @Version 1.0
 */
@Service
public class FactoryApiImpl implements FactoryApi {

    @Resource
    private FactoryService factoryService;

    @Override
    public FactoryRespDTO getFactory(Long id) {
        if (ObjectUtil.isNull(id)){
            return null;
        }
        FactoryDO factory = factoryService.getFactory(id);
        return FactoryConvert.INSTANCE.convert01(factory);
    }

    @Override
    public FactoryRespDTO getFactory(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        FactoryDO factory = factoryService.getFactory(code);
        return FactoryConvert.INSTANCE.convert01(factory);
    }

    @Override
    public Set<Long> getFactoryIds() {
        List<FactoryDO> factoryList = factoryService.getFactoryList();
        return CollectionUtils.convertSet(factoryList, FactoryDO::getId);
    }

    @Override
    public List<FactoryRespDTO> getFactoryList(Set<Long> factoryIds) {
        if (CollectionUtil.isEmpty(factoryIds)) {
            return Collections.emptyList();
        }
        List<FactoryDO> factoryList = factoryService.getFactoryList(factoryIds);
        return FactoryConvert.INSTANCE.convertList04(factoryList);
    }
}
